package com.leancloud.circle.activity;

import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.TextView;

import com.alibaba.android.arouter.facade.annotation.Route;
import com.aries.ui.view.title.TitleBarView;
import com.leancloud.circle.R;
import com.leancloud.circle.adapter.CollectionAdapter;
import com.leancloud.circle.bean.CollectionBean;
import com.leancloud.circle.manage.CirclePathManage;
import com.scwang.smartrefresh.layout.SmartRefreshLayout;
import com.scwang.smartrefresh.layout.api.RefreshLayout;
import com.scwang.smartrefresh.layout.listener.OnRefreshListener;

import java.util.ArrayList;
import java.util.List;

import tech.com.commoncore.base.BaseTitleActivity;

/**
 * 收藏界面
 */
@Route(path = CirclePathManage.CIRCLE_MY_COLLECTION)
public class MyCollectionActivity extends BaseTitleActivity {

    private RecyclerView recyclerView;
    private SmartRefreshLayout smartRefreshLayout;
    private CollectionAdapter collectionAdapter;
    private TextView noDataTx;

    private List<CollectionBean> collectionBeans = new ArrayList<>();

    @Override
    public void setTitleBar(TitleBarView titleBar) {
        titleBar.setTitleMainText("我的收藏");
    }

    @Override
    public int getContentLayout() {
        return R.layout.activity_my_collection;
    }

    @Override
    public void initView(Bundle savedInstanceState) {
        recyclerView = findViewById(R.id.my_collection_recycler);
        smartRefreshLayout = findViewById(R.id.circle_recommend_smart_refresh);
        noDataTx = findViewById(R.id.no_data_value);

        collectionAdapter = new CollectionAdapter(R.layout.circle_layout_item_collection);
        recyclerView.setLayoutManager(new LinearLayoutManager(this));
        recyclerView.setAdapter(collectionAdapter);

        smartRefreshLayout.setOnRefreshListener(new OnRefreshListener() {
            @Override
            public void onRefresh(RefreshLayout refreshLayout) {
                requestData();
            }
        });

        if (collectionBeans.isEmpty()) {
            smartRefreshLayout.autoRefresh();
        }
    }

    private void requestData() {
        collectionBeans.clear();
//        CircleGlobal.getCircleImp().requestCollection(UserGlobal.getCurrentUser().getToken(),
//                1, "20", null, new CircleBack<List<CollectionBean>>() {
//                    @Override
//                    public void onBack(List<CollectionBean> beans, String err) {
//                        smartRefreshLayout.finishRefresh();
//                        if (err == null && beans != null && !beans.isEmpty()) {
//                            collectionBeans = beans;
//                            collectionAdapter.replaceData(beans);
//                            collectionAdapter.notifyDataSetChanged();
//                        } else {
//                            noDataTx.setVisibility(View.VISIBLE);
//                        }
//                    }
//                });
    }
}
